package com.xiaojie.learn.util;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

public class DefalutShorURLUtil extends AbstractShortURLUtil {

    //自增
    private static AtomicLong incr = new AtomicLong();
    //存储容器
    private static ConcurrentHashMap<String,String> container = new ConcurrentHashMap();
    //缓存容器
    private static ConcurrentHashMap<String,String> cache = new ConcurrentHashMap();

    @Override
    String checkCache(String cachekey) {
        return cache.get(cachekey);
    }

    @Override
    void pushCache(String cachekey, int time, String value) {
        cache.put(cachekey,value);
    }

    @Override
    long getShortNum(String SHORT_URL_KEY) {
        return incr.getAndIncrement();
    }

    @Override
    void persist(String shortKey, String longURL) {
        container.put(shortKey,longURL);
    }

    @Override
    String getLong(String shortURL) {
        return container.get(shortURL);
    }

    public static void main(String[] args) {
        DefalutShorURLUtil shorURLUtil = new DefalutShorURLUtil();
        final String honfks = shorURLUtil.getShortURL("honfks", Decimal.D32);
        System.out.println(honfks);
        System.out.println(shorURLUtil.getLongURL(honfks));
    }
}
